/*********************************************************************************
 *      Copyright:  (C) 2022 Zhang xiangyun<1327295677@qq.com>
 *                  All rights reserved.
 *
 *       Filename:  pack.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(07/05/22)
 *         Author:  Zhang xiangyun <1327295677@qq.com>
 *      ChangeLog:  1, Release initial version on "07/05/22 14:38:47"
 *                 
 ********************************************************************************/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include "pack.h"
#include "logger.h"
#include "ds18b20.h"
#include "pack.h"
int get_id(char *serial_id, int size, int sn);
int get_time(char *sample_time);
int packet_data(pack_info_t pack_info,char *pack_buf,int size);

int get_id(char *serial_id, int size, int sn)
{
	if( !serial_id || size<DEVID_LEN )
	{
		log_error("get_id() Invalid input arugments\n");
		return -1;
	}
	memset(serial_id,0,size);
	snprintf(serial_id,size,"RPI#%04d",sn);
	return 0;
}

int get_time(char *sample_time)
{
	struct tm *ptm;
	time_t   now;
	if(!sample_time)
	{
		log_error("get_time() Invalid input arugments\n");
		return -1;
	}
	time(&now);
	ptm=localtime(&now);

	memset(sample_time,0,TIME_LEN);
	snprintf(sample_time,TIME_LEN,"%02i:%02i:%02i",ptm->tm_hour,ptm->tm_min,ptm->tm_sec);

	return 0;
}

int packet_data(pack_info_t pack_info,char *pack_buf,int size)
{

	memset(pack_buf,0,size);
	snprintf(pack_buf,size,"%s/%s/%s",pack_info.serial_id,pack_info.sample_time,pack_info.temper);
	return strlen(pack_buf);
}



